package com.itheima.ydd.common;


import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zihao
 * @version 1.0
 * @date 2022/4/9 0009 zihao
 */
@Data
public class R<T> {
    private Integer errno;
    private String errmsg;
    private T data; //数据
    private Map map = new HashMap(); //动态数据

    public static <T> R<T> success(T object) {
        R<T> r = new R<T>();
        r.data = object;
        r.errno = 0;
        r.errmsg = "成功";
        return r;
    }

    public static <T> R<T> error(String msg) {
        R r = new R();
        r.errmsg = msg;
        r.errno = 1000;
        return r;
    }

    public R<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
